var UserMgr = {};
var userList = {};
var userOnline = 0;
var logger = global.logger;

var User = require('./model/user');

UserMgr.bind = function(userId,hbsocket){
    if(userList[userId]){
        logger.warn('重复绑定：' + userId);
    }

    userList[userId] = new User(userId, hbsocket);
    userOnline++;

    return userList[userId];
};

UserMgr.del = function(userId){
    delete userList[userId];
    userOnline--;
};

UserMgr.get = function(userId){
    return userList[userId];
};

UserMgr.isOnline = function(userId){
    var data = userList[userId];
    if(data != null){
        return true;
    }
    return false;
};

UserMgr.getOnlineCount = function(){
    return userOnline;
}

module.exports = UserMgr;